import { getUserInfoUrl } from "@/command/apiTool";
import { getAction } from "@/command/netTool";
import { useDetail, useList } from "@/hooks";
import * as vant from "vant";
const { showFailToast, showSuccessToast } = vant;
import { useRoute, useRouter } from "vue-router";
export const useRequest = () => {
  //结对详情
  const route = useRoute();
  const router = useRouter();
  const position = localStorage.getItem("positionData") as string;
  const positionJSON = JSON.parse(position) as {
    latitude: string;
    longitude: string;
  };
  console.log("positionJSON", positionJSON);
  const [teamInfo] = useDetail(
    getUserInfoUrl(
      {
        dh: "/api/H5/richHelpFormationApply/large/getUserDetail",
        xh: "/api/H5/richHelpFormationApply/small/getUserDetail",
      },
      {
        userId: route.query.id,
        lat: positionJSON.latitude,
        lng: positionJSON.longitude,
      }
    ),
    {
      address: "",
      entityLogo: "",
      entityName: "",
      id: "",
      jl: "",
      lat: "",
      lng: "",
      logo: "",
      phone: "",
      teamFlag: "", // 结队状态 0未结队 / 1已结队
      userFlag: "", // 关联状态 0没关系 / 1有关系
      agriculturalList: [
        {
          name: "",
          comment: "",
          img: "",
        },
      ],
      sbList: [
        {
          features: "",
          id: "",
          img: "",
          name: "",
          remark: "",
        },
      ],
      productList: [
        {
          img: "",
          name: "",
        },
      ],
    }
  );
  // 大户
  const dhAction = (e: any, type: string) => sendAction("large", e.id, type);
  // 小户
  const xhAction = (e: any, type: string) => sendAction("small", e.id, type);

  const sendAction = (type: any, id: any, applyType: any) => {
    getAction(
      `/api/H5/richHelpFormationApply/${type}/apply?farmerId=${id}&applyType=${applyType}`
    ).then((e) => {
      showSuccessToast("申请成功");
      router.back();
    });
  };

  return {
    teamInfo,
    dhAction,
    xhAction,
  };
};
